<?php
/**
 * User: tridungpham
 * Date: 4/20/11
 * Time: 1:42 PM
 */
 
class Session
{
    private static $instance;
    
    private function __construct()
    {
        if(!session_start())
        {
            exit("Session can not be started");
        }
    }

    static function getInstance()
    {
        if(is_null(self::$instance))
            self::$instance = new Session();
        return self::$instance;
    }

    /**
     * @param  $name Ten truong trong session
     * @param  $value Gia tri cua cookie
     * @return void
     */
    public function set($name,$value)
    {
        $_SESSION[$name] = $value;
    }

    public function get($name)
    {
        if(isset($_SESSION[$name]))
            return $_SESSION[$name];
        else
            exit("session $_SESSION[$name] does not exist");
    }

    /**
     * @param  $key Ten truong trong session
     * @return void
     */
    public function remove($key)
    {
        if(isset($_SESSION[$key]))
            unset($_SESSION[$key]);
    }

    /**
     * @param  $key Ten truong trong session
     * @return bool
     */
    public function isExist($key)
    {
        if(isset($_SESSION[$key]))
            return TRUE;
        else
            return FALSE;
    }

}